import type { VxeTableGridOptions } from '@vben/plugins/vxe-table';

import type { VbenFormSchema } from '#/adapter/form';
import type { OnActionClickFn } from '#/adapter/vxe-table';
import type { ManualInspectionItemModel } from '#/api/equipment/models';

/**
 * 获取编辑表单的字段配置。
 */
export function useSchema(): VbenFormSchema[] {
  return [
    {
      component: 'Input',
      fieldName: 'subjectName',
      label: '点检项名称',
      rules: 'required',
    },
    {
      component: 'Textarea',
      componentProps: {
        showCount: true,
        maxlength: 128,
      },
      fieldName: 'standard',
      label: '点检项标准',
    },
  ];
}

/**
 * 获取表格列配置。
 * @param onActionClick 表格操作按钮点击事件
 */
export function useColumns(
  onActionClick?: OnActionClickFn<ManualInspectionItemModel>,
): VxeTableGridOptions<ManualInspectionItemModel>['columns'] {
  return [
    { type: 'seq', width: 60 },
    { field: 'subjectName', title: '点检项名称', width: 220 },
    { field: 'standard', title: '点检项标准', minWidth: 160 },
    {
      cellRender: {
        attrs: {
          nameField: 'subjectName',
          nameTitle: '点检项',
          onClick: onActionClick,
        },
        name: 'CellOperation',
        options: [
          'edit', // 默认的编辑按钮
          'delete', // 默认的删除按钮
        ],
      },
      field: 'operation',
      fixed: 'right',
      title: '操作',
      width: 120,
    },
  ];
}
